import math

# 最大迭代次数
max_iteration = 1000


def f(x):
    return x * math.exp(x) - 1


def df(x):
    return math.exp(x) + x * math.exp(x)


def do_iterate():
    error = float(input("请输入精度要求: "))
    x1 = float(input("请输入迭代初始值: "))
    flag = 0
    for i in range(max_iteration):
        x0 = x1
        x1 = x0 - f(x0) / df(x0)
        if abs(x1 - x0) <= error:
            flag = 1
            break
    if flag == 1:
        print("方程f(x)=0的根为:", x1)
    else:
        print("迭代次数超过上限")


if __name__ == '__main__':
    do_iterate()
